home *** CD-ROM | disk | FTP | other *** search
- //PEMDAS 1.0
- //Code in the widget bundle (c) 2006 Michael Filippone.
- //Code in /System/Library/WidgetResources/AppleClasses/ (c) Apple Computer.
- //Visit http://www.donkeyentertainment.com to file bug reports or feature requests.
- var thisVersionNumber="1.0", currentReleaseNumber, currentReleaseMessage, currentReleaseURL;
- document.addEventListener("keypress", keyPressed, true);
- var answerDiv, formulaDiv, formulaCacheDiv, formulaCacheParentDiv, variableCacheDiv;
- var previousKeyEntered='';
- var preferencesAnswerFormatting=1;
- var preferencesProgrammerMode=0;
- var preferencesPrecision=0;
- var preferencesRadians=1;
- var preferencesThousandsSeperators=0;
- var preferencesWhatToCopy=1;
- var lastCheckedTime=0;
- var preferencesIgnoreUpdates=0;
- var preferencesRemindLater=0;
- var commaLocale=0;
- var fseLength=4;
- var currentAnswerNumber=1;
- var answer={errorMessage:'1', answer:''};
- var formulaScrollTimer;
- var currentScrollKey=63235;
- var formula='';
- var finalAnswer;
- var calculationCount=0;
- var justRecalculatedCachedFormula=false;
- var justCalculatedEquation=false;
- var growboxInset, initialClickOffset, initialClick;
- var currentcursorposition=0;
- var curformula=1;
- var cursorPixelOffset=22;
- var resizeToX=480, resizeToY=385;
- var fontwidths=new Array();
- fontwidths[33]=3;
- fontwidths[37]=11;
- fontwidths[40]=3;
- fontwidths[41]=3;
- fontwidths[42]=4;
- fontwidths[43]=7;
- fontwidths[44]=3;
- fontwidths[45]=3;
- fontwidths[46]=3;
- fontwidths[47]=3;
- fontwidths[48]=6;
- fontwidths[49]=6;
- fontwidths[50]=6;
- fontwidths[51]=6;
- fontwidths[52]=6;
- fontwidths[53]=6;
- fontwidths[54]=6;
- fontwidths[55]=6;
- fontwidths[56]=6;
- fontwidths[57]=6;
- fontwidths[61]=7;
- fontwidths[94]=5;
- fontwidths[65]=8;
- fontwidths[66]=8;
- fontwidths[67]=8;
- fontwidths[68]=8;
- fontwidths[69]=8;
- fontwidths[70]=7;
- fontwidths[71]=9;
- fontwidths[72]=8;
- fontwidths[73]=3;
- fontwidths[74]=6;
- fontwidths[75]=8;
- fontwidths[76]=6;
- fontwidths[77]=10;
- fontwidths[78]=8;
- fontwidths[79]=9;
- fontwidths[80]=8;
- fontwidths[81]=9;
- fontwidths[82]=8;
- fontwidths[83]=8;
- fontwidths[84]=7;
- fontwidths[85]=8;
- fontwidths[86]=8;
- fontwidths[87]=11;
- fontwidths[88]=8;
- fontwidths[89]=8;
- fontwidths[90]=7;
- fontwidths[97]=6;
- fontwidths[98]=6;
- fontwidths[99]=6;
- fontwidths[100]=6;
- fontwidths[101]=6;
- fontwidths[102]=3;
- fontwidths[103]=6;
- fontwidths[104]=6;
- fontwidths[105]=2;
- fontwidths[106]=2;
- fontwidths[107]=6;
- fontwidths[108]=2;
- fontwidths[109]=10;
- fontwidths[110]=6;
- fontwidths[111]=6;
- fontwidths[112]=6;
- fontwidths[113]=6;
- fontwidths[114]=3;
- fontwidths[115]=6;
- fontwidths[116]=3;
- fontwidths[117]=6;
- fontwidths[118]=6;
- fontwidths[119]=8;
- fontwidths[120]=6;
- fontwidths[121]=6;
- fontwidths[122]=6;
- fontwidths[192]=8;
- fontwidths[193]=8;
- fontwidths[194]=8;
- fontwidths[195]=8;
- fontwidths[196]=8;
- fontwidths[197]=8;
- fontwidths[198]=12;
- fontwidths[199]=8;
- fontwidths[200]=8;
- fontwidths[201]=8;
- fontwidths[202]=8;
- fontwidths[203]=8;
- fontwidths[204]=3;
- fontwidths[205]=3;
- fontwidths[206]=3;
- fontwidths[207]=3;
- fontwidths[208]=8;
- fontwidths[209]=8;
- fontwidths[210]=9;
- fontwidths[211]=9;
- fontwidths[212]=9;
- fontwidths[213]=9;
- fontwidths[214]=9;
- fontwidths[216]=9;
- fontwidths[217]=8;
- fontwidths[218]=8;
- fontwidths[219]=8;
- fontwidths[220]=8;
- fontwidths[221]=8;
- fontwidths[222]=8;
- fontwidths[223]=7;
- fontwidths[224]=6;
- fontwidths[225]=6;
- fontwidths[226]=6;
- fontwidths[227]=6;
- fontwidths[228]=6;
- fontwidths[229]=6;
- fontwidths[230]=11;
- fontwidths[231]=6;
- fontwidths[232]=6;
- fontwidths[233]=6;
- fontwidths[234]=6;
- fontwidths[235]=6;
- fontwidths[236]=3;
- fontwidths[237]=3;
- fontwidths[238]=3;
- fontwidths[239]=3;
- fontwidths[240]=6;
- fontwidths[241]=6;
- fontwidths[242]=6;
- fontwidths[243]=6;
- fontwidths[244]=6;
- fontwidths[245]=6;
- fontwidths[246]=6;
- fontwidths[248]=7;
- fontwidths[249]=6;
- fontwidths[250]=6;
- fontwidths[251]=6;
- fontwidths[252]=6;
- fontwidths[253]=6;
- fontwidths[254]=6;
- fontwidths[255]=6;
- function printf(stringToPrint)
- {
- }
- function clear()
- {
- }
- function onLoadScript()
- {
- answerDiv = document.getElementById('answerDiv');
- formulaDiv = document.getElementById('formulaDiv');
- variableCacheDiv = document.getElementById('variableCacheDiv');
- formulaCacheDiv = document.getElementById('formulaCacheDiv');
- formulaCacheParentDiv = document.getElementById('formulaCacheParentDiv');
- consolediv = document.getElementById('consoleDiv');
- cursordiv = document.getElementById('cursorDiv');
- loadAppleButtons();
- scrollbar = new AppleVerticalScrollbar(document.getElementById("formulaCacheScrollBar"));
- scrollArea = new AppleScrollArea(document.getElementById("formulaCacheParentDiv"), scrollbar);
- scrollArea.scrollsHorizontally = false;
- scrollArea.singlepressScrollPixels = 25;
- answerscrollbar = new AppleVerticalScrollbar(document.getElementById("answerCacheScrollBar"));
- answerscrollArea = new AppleScrollArea(document.getElementById("answerCacheParentDiv"), answerscrollbar);
- answerscrollArea.scrollsHorizontally = false;
- answerscrollArea.singlepressScrollPixels = 25;
- scrollbar._track.style.height='10px';
- scrollbar._track.children[0].style.background = "url(" + scrollbar.trackMiddlePath + ") repeat-y top left";
- scrollbar._track.children[2].style.background = "url(" + scrollbar.trackMiddlePath + ") repeat-y top left";
- answerscrollbar._track.children[0].style.background = "url(" + scrollbar.trackMiddlePath + ") repeat-y top left";
- answerscrollbar._track.children[2].style.background = "url(" + scrollbar.trackMiddlePath + ") repeat-y top left";
- formulascrollbar = new AppleHorizontalScrollbar(document.getElementById("formulaScrollBar"));
- formulascrollArea = new AppleScrollArea(document.getElementById("formulaParentDiv"), formulascrollbar);
- formulascrollArea.scrollsVertically = false;
- formulascrollArea.singlepressScrollPixels = 25;
- tdstretch = new PDWindowStretch();
- loadPreferences();
- implementPreferences();
- setLocalization();
- updateDisplay();
- checkForUpdates();
- if (window.widget) {
- widget.setPreferenceForKey(thisVersionNumber,"thisVersionNumber");
- }
- if (commaLocale) {
- document.getElementById('radixPoint').src="images/numbers/comma.png";
- }
- }
- function loadPreferences()
- {
- if (window.widget) {
- if (widget.preferenceForKey("preferencesPrecision")) {
- preferencesPrecision=parseInt(widget.preferenceForKey("preferencesPrecision"));
- if (preferencesPrecision<0 || preferencesProgrammerMode>16) {
- preferencesPrecision=0;
- }
- }
- if (widget.preferenceForKey("preferencesProgrammerMode")) {
- preferencesProgrammerMode=parseInt(widget.preferenceForKey("preferencesProgrammerMode"));
- if (preferencesProgrammerMode!==0 && preferencesProgrammerMode!==1) {
- preferencesProgrammerMode=0;
- }
- }
- if (widget.preferenceForKey("preferencesAnswerFormatting")) {
- preferencesAnswerFormatting=parseInt(widget.preferenceForKey("preferencesAnswerFormatting"));
- if (preferencesProgrammerMode) {
- if (preferencesAnswerFormatting<1 || preferencesAnswerFormatting>7) {
- preferencesAnswerFormatting=1;
- }
- } else {
- if (preferencesAnswerFormatting<1 || preferencesAnswerFormatting>4) {
- preferencesAnswerFormatting=1;
- }
- }
- }
- if (!isNaN(parseInt(widget.preferenceForKey("preferencesRadians")))) {
- preferencesRadians=parseInt(widget.preferenceForKey("preferencesRadians"));
- if (preferencesRadians!==0 && preferencesRadians!==1) {
- preferencesRadians=1;
- }
- }
- if (!isNaN(parseInt(widget.preferenceForKey("preferencesThousandsSeperators")))) {
- preferencesThousandsSeperators=parseInt(widget.preferenceForKey("preferencesThousandsSeperators"));
- if (preferencesThousandsSeperators!==0 && preferencesThousandsSeperators!==1) {
- preferencesThousandsSeperators=0;
- }
- }
- if (widget.preferenceForKey("preferencesIgnoreUpdates")) {
- preferencesIgnoreUpdates=parseInt(widget.preferenceForKey("preferencesIgnoreUpdates"));
- if (preferencesIgnoreUpdates!==0 && preferencesIgnoreUpdates!==1) {
- preferencesIgnoreUpdates=0;
- }
- }
- }
- }
- function implementPreferences()
- {
- if (preferencesProgrammerMode) {
- fseLength=7;
- document.getElementById('widgetBackProgrammerMode').checked=true;
- }
- formatPreferenceBar();
- if (preferencesPrecision) {
- document.getElementById('widgetBackPrecision').value=preferencesPrecision;
- }
- if (preferencesThousandsSeperators) {
- document.getElementById('widgetBackThousandsSeparators').checked=true;
- } else {
- document.getElementById('widgetBackThousandsSeparators').checked=false;
- }
- changePreferencesAnswerFormatting(preferencesAnswerFormatting);
- changePreferencesRadians(preferencesRadians);
- }
- function loadAppleButtons()
- {
- flipper = new AppleInfoButton(document.getElementById("flipper"), document.getElementById("front"), "white", "white", showBack);
- expander = new AppleInfoButton(document.getElementById("expander"), document.getElementById("front"), "white", "white", expandCalculator);
- glassButton = new AppleGlassButton(document.getElementById("doneButton"), "Done", showFront);
- expander._flipLabel.src="images/infoBar/plus.png";
- }
- function pasteHandler(event)
- {
- var tempVar=event.clipboardData.getData('Text');
- var i, stringToAdd='', curkeycode;
- if (commaLocale) {
- tempVar=tempVar.replace(/\./g,',');
- } else {
- tempVar=tempVar.replace(/,/g,'.');
- }
- for (i=0; i<tempVar.length; i++) {
- curkeycode=tempVar.charCodeAt(i);
- if ((curkeycode>47 && curkeycode<58) || (curkeycode>64 && curkeycode<91) || (curkeycode>96 && curkeycode<123) || (curkeycode>191 && curkeycode<256 && curkeycode!=215 && curkeycode!=237)) {
- stringToAdd=stringToAdd+''+tempVar.charAt(i);
- } else {
- switch (curkeycode) {
- case 37: case 40: case 41: case 42: case 43: case 44: case 45: case 46: case 47: case 61: case 94:
- stringToAdd=stringToAdd+''+tempVar.charAt(i);
- break;
- }
- }
- if (tempVar.charCodeAt(i)==10 || tempVar.charCodeAt(i)==3 || tempVar.charCodeAt(i)==13)
- break;
- }
- addToMainDisplay(stringToAdd);
- updateDisplay();
- event.preventDefault();
- event.stopPropagation();
- }
- function copyHandler(event)
- {
- if (preferencesWhatToCopy) {
- event.clipboardData.setData('Text', formula);
- } else
- event.clipboardData.setData('Text', answerDiv.innerHTML);
- event.preventDefault();
- event.stopPropagation();
- }
- function showCursorLocation(event)
- {
- var xClickLocation=event.pageX-cursorPixelOffset+formulascrollArea.content.scrollLeft;
- if (getFormulaPixelLength()<=xClickLocation) {
- currentcursorposition=0;
- updateCursorDiv();
- } else {
- getCursorPositionWithCoords(xClickLocation);
- }
- preferencesWhatToCopy=1;
- }
- function getFormulaPixelLength()
- {
- var i, pixelLength=0, formulaLength=formula.length;
- for (i=0; i<formulaLength; i++) {
- pixelLength+=fontwidths[formula.charCodeAt(i)]+1;
- }
- return pixelLength;
- }
- function getCursorPositionWithCoords(xlocation)
- {
- justCalculatedEquation=false;
- var i, cursorpositionpixels=0;
- for (i=0; i<=formula.length; i++) {
- if (cursorpositionpixels>=xlocation) {
- currentcursorposition=i-formula.length-1;
- currentcursorposition++;
- if ((cursorpositionpixels-xlocation)>(fontwidths[formula.charCodeAt(i-1)]-2)*0.66)
- {
- currentcursorposition--;
- cursorpositionpixels-=(fontwidths[formula.charCodeAt(i-1)]+1);
- }
- break;
- }
- cursorpositionpixels+=fontwidths[formula.charCodeAt(i)]+1;
- }
- cursordiv.style.marginLeft=Math.round(cursorpositionpixels);
- }
- function updateCursorDiv()
- {
- var i, cursorpositionpixels=0;
- var spottogoto=formula.length-1+currentcursorposition;
- for (i=0; i<=spottogoto; i++)
- {
- cursorpositionpixels+=fontwidths[formula.charCodeAt(i)]+1;
- }
- if (!isNaN(cursorpositionpixels))
- {
- cursordiv.style.marginLeft=Math.round(cursorpositionpixels);
- }
- else
- {
- if (isNaN(cursorpositionpixels)) cursordiv.style.marginLeft=0;
- else cursordiv.style.marginLeft=cursorPixelOffset;
- }
- updateFormulaScrollArea();
- }
- function addFormulaToCache(formula) {
- formulaCacheDiv.innerHTML=formulaCacheDiv.innerHTML + '<div id=\"formulaCacheDiv' + curformula + '\" onclick=\"recalculateCachedFormula(this);\">' + formula + '</div>';
- curformula++;
- scrollArea.refresh();
- var tempvar=scrollArea.content.scrollHeight - scrollArea.viewHeight-14;
- if (tempvar<=0 || tempvar==scrollArea.content.scrollTop) scrollArea.verticalScrollTo(scrollArea.content.scrollHeight - scrollArea.viewHeight);
- }
- function addVariableToMainDisplay(variableName)
- {
- if (justCalculatedEquation)
- formula='';
- addToMainDisplay(variableName);
- updateDisplay();
- justCalculatedEquation=false;
- }
- function updateVariableCacheDivScrollArea()
- {
- answerscrollArea.refresh();
- var tempvar=answerscrollArea.content.scrollHeight - answerscrollArea.viewHeight-14;
- if (tempvar<=0 || tempvar==answerscrollArea.content.scrollTop)
- answerscrollArea.verticalScrollTo(answerscrollArea.content.scrollHeight - answerscrollArea.viewHeight);
- }
- function addToMainDisplay(numbertoadd)
- {
- var formulaLength=formula.length;
- document.getElementById("tempDiv").innerHTML=numbertoadd;
- numbertoadd=document.getElementById("tempDiv").innerHTML;
- formula=formula.substring(0, formulaLength+currentcursorposition)+''+numbertoadd+formula.substring(formulaLength+currentcursorposition, formulaLength);
- updateDisplay();
- }
- function keyPressed(event)
- {
- if (event.metaKey) return;
- if (event.shiftKey) {
- switch (event.charCode) {
- case 8:
- keyPressHandler(63289);
- break;
- case 63234:
- keyPressHandler(-63234);
- break;
- case 63235:
- keyPressHandler(-63235);
- break;
- default:
- keyPressHandler(event.charCode);
- break;
- }
- } else
- keyPressHandler(event.charCode);
- event.preventDefault();
- }
- function keyPressHandler(keypressedcode)
- {
- var curlength;
- var curenternum=0;
- if (keypressedcode==3 || keypressedcode==13) {
- displayAnswer(formula);
- } else if (keypressedcode==63289) {
- if (previousKeyEntered==63289)
- resetWidget();
- else
- clearDisplay();
- } else if (keypressedcode==63272) {
- if (currentcursorposition<0) {
- curlength=formula.length;
- formula=formula.substring(0, curlength+currentcursorposition)+''+ formula.substring(curlength+1+currentcursorposition, curlength);
- currentcursorposition++;
- }
- updateDisplay();
- } else if (keypressedcode==-63234) {
- if (--preferencesAnswerFormatting<1)
- preferencesAnswerFormatting=fseLength;
- changePreferencesAnswerFormatting(preferencesAnswerFormatting);
- } else if (keypressedcode==-63235) {
- if (++preferencesAnswerFormatting>fseLength)
- preferencesAnswerFormatting=1;
- changePreferencesAnswerFormatting(preferencesAnswerFormatting);
- } else if (keypressedcode==63234) {
- currentcursorposition--;
- if (formula.length-1+currentcursorposition<-1)
- currentcursorposition++;
- updateCursorDiv();
- } else if (keypressedcode==63235) {
- currentcursorposition++;
- if (currentcursorposition>0) currentcursorposition=0;
- updateCursorDiv();
- } else if (keypressedcode==63232) {
- currentcursorposition=0-formula.length;
- updateCursorDiv();
- } else if (keypressedcode==63233) {
- currentcursorposition=0;
- updateCursorDiv();
- } else if (keypressedcode==8) {
- curlength=formula.length;
- formula=formula.substring(0, curlength-1+currentcursorposition)+'' + formula.substring(curlength+currentcursorposition, curlength);
- updateDisplay();
- } else if ((keypressedcode>47 && keypressedcode<58) || (keypressedcode>64 && keypressedcode<91) || (keypressedcode>96 && keypressedcode<123) || (keypressedcode>191 && keypressedcode<256 && keypressedcode!=215 && keypressedcode!=237)) {
- curenternum=String.fromCharCode(keypressedcode);
- if (justCalculatedEquation && curenternum && !justRecalculatedCachedFormula) {
- formula='';
- currentcursorposition=0;
- }
- addToMainDisplay(curenternum);
- } else {
- switch(keypressedcode)
- {
- case 37: curenternum='%'; break;
- case 40: curenternum='('; break;
- case 41: curenternum=')'; break;
- case 42: curenternum='*';
- if (justCalculatedEquation && !justRecalculatedCachedFormula) {
- curenternum='ans*';
- currentcursorposition=0;
- }
- break;
- case 43: curenternum='+';
- if (justCalculatedEquation && !justRecalculatedCachedFormula) {
- curenternum='ans+';
- currentcursorposition=0;
- }
- break;
- case 44:
- if (commaLocale)
- curenternum=',';
- else
- curenternum='.'; break;
- case 45: curenternum='-';
- if (justCalculatedEquation && !justRecalculatedCachedFormula) {
- curenternum='ans-';
- currentcursorposition=0;
- }
- break;
- case 46:
- if (commaLocale)
- curenternum=',';
- else
- curenternum='.'; break;
- case 47: curenternum='/';
- if (justCalculatedEquation && !justRecalculatedCachedFormula) {
- curenternum='ans/';
- currentcursorposition=0;
- }
- break;
- case 61: curenternum='='; break;
- case 94: curenternum='^';
- if (justCalculatedEquation && !justRecalculatedCachedFormula) {
- curenternum='ans^';
- currentcursorposition=0;
- }
- break;
- }
- if (justCalculatedEquation && curenternum && !justRecalculatedCachedFormula) {
- formula='';
- currentcursorposition=0;
- }
- addToMainDisplay(curenternum);
- }
- if (keypressedcode!=3 && keypressedcode!=13 && keypressedcode!=61)
- justCalculatedEquation=false;
- justRecalculatedCachedFormula=false;
- previousKeyEntered=keypressedcode;
- setTimeout("previousKeyEntered='';", 400);
- }
- var calculationTimerCounter=0;
- var calculationTimer;
- function displayAnswer(equationToCalculate)
- {
- answer=calculateEquation(equationToCalculate);
- answerDiv.style.fontSize='17px';
- answerDiv.style.top='35px';
- if (answer.errorMessage) {
- answerDiv.style.fontSize='12px';
- answerDiv.style.top='38px';
- answerDiv.innerHTML='Error: '+answer.errorMessage;
- } else {
- finalAnswer=new PDAnswer(answer.answer);
- answerDiv.innerHTML=finalAnswer.getAnswer(preferencesAnswerFormatting);
- setVariableInCacheDisplay(answer.answer, 'ans');
- if (answer.variableStoredIn) {
- answerDiv.innerHTML=answer.variableStoredIn+"="+answerDiv.innerHTML;
- updateAnswerCache(answer.answer,0);
- setVariableInCacheDisplay(answer.answer, answer.variableStoredIn);
- } else {
- updateAnswerCache(answer.answer);
- setVariableInCacheDisplay(answer.answer, 'ans'+(currentAnswerNumber-1));
- }
- if (!justRecalculatedCachedFormula)
- addFormulaToCache(equationToCalculate);
- justCalculatedEquation=true;
- }
- calculationCount++;
- if (calculationCount>30) {
- checkForUpdates();
- calculationCount=1;
- }
- }
- function redisplayAnswer()
- {
- if (!answer.errorMessage) {
- answerDiv.innerHTML=finalAnswer.getAnswer(preferencesAnswerFormatting);
- }
- }
- function clearDisplay()
- {
- resetVariables();
- updateDisplay();
- }
- function resetWidget()
- {
- resetVariables();
- answerDiv.style.fontSize='17px';
- variableNames=new Array();
- variables=new Array();
- variableIndex=0;
- setVariable('pi', Math.PI);
- answer={errorMessage:'1', answer:''};
- currentAnswerNumber=1;
- curformula=1;
- answerDiv.innerHTML='0';
- formulaCacheDiv.innerHTML='';
- variableCacheDiv.innerHTML="";
- answerscrollArea.refresh();
- answerscrollbar.refresh();
- scrollArea.refresh();
- scrollbar.refresh();
- updateDisplay();
- calculationCount=0;
- checkForUpdates();
- }
- function resetVariables()
- {
- formula='';
- currentcursorposition=0;
- }
- function updateDisplay()
- {
- updateCursorDiv();
- formulaDiv.innerHTML=formula;
- clear();
- updateFormulaScrollArea();
- }
- function updateFormulaScrollArea()
- {
- formulaDiv.style.width=getFormulaPixelLength()+1;
- formulascrollArea.refresh();
- formulascrollbar.refresh();
- formulaBarWidth=parseInt(document.getElementById("formulaParentDiv").style.width);
- if (formulascrollArea.content.scrollWidth>formulaBarWidth) {
- if (parseInt(cursordiv.style.marginLeft)<formulascrollArea.content.scrollLeft) {
- formulascrollArea.horizontalScrollTo(parseInt(cursordiv.style.marginLeft));
- } else if (parseInt(cursordiv.style.marginLeft)>(formulascrollArea.content.scrollLeft+formulaBarWidth)) {
- formulascrollArea.horizontalScrollTo(parseInt(cursordiv.style.marginLeft)-formulaBarWidth+1);
- }
- }
- }
- function recalculateCachedFormula(curformuladiv)
- {
- resetVariables();
- formula=curformuladiv.innerHTML;
- updateDisplay();
- justRecalculatedCachedFormula=true;
- displayAnswer(formula);
- }
- function expandCalculator()
- {
- if (tdstretch.toWidth) {
- expander._flipLabel.src="images/infoBar/minus.png";
- document.getElementById("resize").style.display = 'block';
- if (window.widget) window.resizeTo(306+tdstretch.maxWidth, 243+tdstretch.maxHeight);
- } else {
- expander._flipLabel.src="images/infoBar/plus.png";
- }
- tdstretch.stretch(event);
- }
- function setWidgetWidth(offset)
- {
- var off297=offset+297;
- var off279=offset+279;
- document.getElementById("topShadow").style.width=off279;
- document.getElementById("topShadowRight").style.left=off279;
- document.getElementById("formulaBar").style.width=off279;
- document.getElementById("formulaBarRight").style.left=off279;
- document.getElementById("preferencesBar").style.width=off297;
- document.getElementById("preferencesBarRight").style.left=off297;
- document.getElementById("mainStretchingBody").style.width = off297;
- document.getElementById("mainStretchingBodyRight").style.left=off297;
- document.getElementById("infoBar").style.width = off279;
- document.getElementById("infoBarRight").style.left=off279;
- document.getElementById("bottomShadow").style.width = off279;
- document.getElementById("bottomShadowRight").style.left=off279;
- document.getElementById("formulaParentDiv").style.width=250+offset;
- document.getElementById("preferencesBarContainer").style.width=288+offset;
- document.getElementById("preferenceBarShadow").style.width=288+offset;
- document.getElementById("answerDiv").style.width=247+offset;
- document.getElementById("answerCacheParentDiv").style.width=116+offset;
- document.getElementById("resize").style.left = 278+offset;
- if (offset<120) {
- document.getElementById("bottomHighlightDiv").style.width=283+offset-offset/120*18;
- } else {
- document.getElementById("bottomHighlightDiv").style.width=265+offset;
- document.getElementById("variableCacheDiv").style.width=offset-4;
- document.getElementById("answerCacheContainerDiv").style.width=offset-2;
- document.getElementById("formulaCacheContainerDiv").style.width=288+offset;
- document.getElementById("formulaCacheParentDiv").style.width=281+offset;
- }
- }
- function setWidgetHeight(offset)
- {
- var off130=130+offset;
- document.getElementById("mainStretchingBody").style.height = off130;
- document.getElementById("mainStretchingBodyRight").style.height = off130;
- document.getElementById("mainBodyBreak").style.height = off130;
- document.getElementById("bottomHighlightDiv").style.top =212+offset;
- document.getElementById("resize").style.top =213+offset;
- document.getElementById("infoBar").style.top =208+offset;
- document.getElementById("infoBarRight").style.top =208+offset;
- document.getElementById("bottomShadow").style.top =230+offset;
- document.getElementById("bottomShadowRight").style.top =230+offset;
- if (offset>99) {
- document.getElementById("formulaCacheScrollBar").style.height=offset-2;
- document.getElementById("formulaCacheParentDiv").style.height=offset-2;
- scrollArea.verticalScrollTo(scrollArea.content.scrollTop);
- scrollArea.refresh();
- }
- }
- function resizeMouseDown(event)
- {
- document.addEventListener("mousemove", resizeMouseMove, true);
- document.addEventListener("mouseup", resizeMouseUp, true);
- var tempx=parseInt(document.getElementById("resize").style.left);
- var tempy=parseInt(document.getElementById("resize").style.top);
- var initialWidth=parseInt(document.getElementById("preferencesBar").style.width);
- var initialHeight=parseInt(document.getElementById("mainBodyBreak").style.height);
- initialClick={x:event.x, y:event.y};
- initialValues={initialWidthOffset:(initialWidth-297), initialHeightOffset:(initialHeight-130)};
- event.stopPropagation();
- event.preventDefault();
- }
- function resizeMouseMove(event)
- {
- var x = event.x-initialClick.x;
- var y = event.y-initialClick.y;
- var offsetx=initialValues.initialWidthOffset+x, offsety=initialValues.initialHeightOffset+y;
- if (offsetx>123) {
- setWidgetWidth(offsetx);
- } else {
- setWidgetWidth(120);
- offsetx=120;
- }
- if (offsety>103)
- {
- setWidgetHeight(offsety);
- } else {
- setWidgetHeight(100);
- offsety=100;
- }
- if (window.widget) window.resizeTo(offsetx+306,offsety+243);
- event.stopPropagation();
- event.preventDefault();
- }
- function resizeMouseUp(event)
- {
- document.removeEventListener("mousemove", resizeMouseMove, true);
- document.removeEventListener("mouseup", resizeMouseUp, true);
- var x = event.x-initialClick.x;
- var y = event.y-initialClick.y;
- var offsetx=initialValues.initialWidthOffset+x, offsety=initialValues.initialHeightOffset+y;
- if (offsetx<120)
- offsetx=120;
- if (offsety<100)
- offsety=100;
- tdstretch.maxWidth=offsetx;
- tdstretch.maxHeight=offsety;
- tdstretch.fromWidth=offsetx;
- tdstretch.fromHeight=offsety;
- event.stopPropagation();
- event.preventDefault();
- }
- function changePreferencesAnswerFormatting(toSwitchTo)
- {
- var imagepath='images/preferencesBar/';
- var onArray=new Array('','','','','','','');
- onArray[toSwitchTo-1]='Selected';
- preferencesAnswerFormatting=toSwitchTo;
- document.getElementById('preferenceBarFlo').src=imagepath+'flo'+onArray[0]+'.png';
- document.getElementById('preferenceBarSci').src=imagepath+'sci'+onArray[1]+'.png';
- document.getElementById('preferenceBarEng').src=imagepath+'eng'+onArray[2]+'.png';
- document.getElementById('preferenceBarPercent').src=imagepath+'percent'+onArray[3]+'.png';
- document.getElementById('preferenceBarBin').src=imagepath+'bin'+onArray[4]+'.png';
- document.getElementById('preferenceBarOct').src=imagepath+'oct'+onArray[5]+'.png';
- document.getElementById('preferenceBarHex').src=imagepath+'hex'+onArray[6]+'.png';
- redisplayAnswer();
- if (window.widget) {
- widget.setPreferenceForKey(preferencesAnswerFormatting,"preferencesAnswerFormatting");
- }
- }
- function changePreferencesRadians(toSwitchTo)
- {
- var imagepath='images/preferencesBar/';
- var onArray=new Array('','');
- onArray[toSwitchTo]='Selected';
- document.getElementById('preferenceBarRad').src=imagepath+'rad'+onArray[1]+'.png';
- document.getElementById('preferenceBarDeg').src=imagepath+'deg'+onArray[0]+'.png';
- preferencesRadians=toSwitchTo;
- if (window.widget) {
- widget.setPreferenceForKey(preferencesRadians,"preferencesRadians");
- }
- }
- function changePreferencesProgrammerMode()
- {
- if (document.getElementById("widgetBackProgrammerMode").checked) {
- preferencesProgrammerMode=1;
- formatPreferenceBar();
- } else {
- preferencesProgrammerMode=0;
- formatPreferenceBar();
- }
- if (preferencesProgrammerMode) {
- fseLength=7;
- } else {
- fseLength=4;
- if (preferencesAnswerFormatting>4) {
- preferencesAnswerFormatting=1;
- }
- }
- changePreferencesAnswerFormatting(preferencesAnswerFormatting);
- if (window.widget) {
- widget.setPreferenceForKey(preferencesProgrammerMode,"preferencesProgrammerMode");
- }
- }
- function formatPreferenceBar()
- {
- if (preferencesProgrammerMode) {
- document.getElementById('preferenceBarFlo').style.left='1%';
- document.getElementById('preferenceBarSci').style.left='11%';
- document.getElementById('preferenceBarEng').style.left='21%';
- document.getElementById('preferenceBarPercent').style.left='30%';
- document.getElementById('preferenceBarBin').style.display='block';
- document.getElementById('preferenceBarOct').style.display='block';
- document.getElementById('preferenceBarHex').style.display='block';
- document.getElementById('preferenceBarDivider').style.left='73%';
- document.getElementById('preferenceBarRad').style.left='77%';
- document.getElementById('preferenceBarDeg').style.left='87%';
- } else {
- document.getElementById('preferenceBarFlo').style.left='2%';
- document.getElementById('preferenceBarSci').style.left='16%';
- document.getElementById('preferenceBarEng').style.left='30%';
- document.getElementById('preferenceBarPercent').style.left='44%';
- document.getElementById('preferenceBarBin').style.display='none';
- document.getElementById('preferenceBarOct').style.display='none';
- document.getElementById('preferenceBarHex').style.display='none';
- document.getElementById('preferenceBarDivider').style.left='61%';
- document.getElementById('preferenceBarRad').style.left='69%';
- document.getElementById('preferenceBarDeg').style.left='84%';
- }
- }
- function changePreferencesPrecision()
- {
- preferencesPrecision=parseInt(document.getElementById("widgetBackPrecision").value);
- if (calculationCount) {
- redisplayAnswer();
- }
- if (window.widget) {
- widget.setPreferenceForKey(preferencesPrecision,"preferencesPrecision");
- }
- }
- function changePreferencesThousandsSeparators()
- {
- if (document.getElementById("widgetBackThousandsSeparators").checked)
- preferencesThousandsSeperators=1;
- else
- preferencesThousandsSeperators=0;
- if (calculationCount) {
- finalAnswer.reformatNumbers();
- redisplayAnswer();
- }
- if (window.widget) {
- widget.setPreferenceForKey(preferencesThousandsSeperators,"preferencesThousandsSeperators");
- }
- }
- function turnOnNumber(currentImage, imageName)
- {
- currentImage.src='images/numbers/'+imageName+'on.png';
- }
- function turnOffNumber(currentImage, imageName)
- {
- currentImage.src='images/numbers/'+imageName+'.png';
- }
- function PDWindowStretch()
- {
- this.duration = 300;
- this.multiplier = 1;
- this.minWidth=0;
- this.maxWidth=120;
- this.minHeight=0;
- this.maxHeight=100;
- this.fromWidth = this.minWidth;
- this.toWidth = this.maxWidth;
- this.fromHeight = this.minHeight;
- this.toHeight = this.maxHeight;
- this.stretchAnimator = null;
- var self=this;
- this.nextFrame = function (animation, now, first, done)
- {
- setWidgetWidth(now);
- }
- this.nextFrameHeight = function (animation, now, first, done)
- {
- setWidgetHeight(now);
- document.getElementById('resize').style.opacity=now/100;
- }
- this.flipWidth = function ()
- {
- if (self.toWidth == self.maxWidth) {
- self.toWidth = self.minWidth;
- self.fromWidth = self.maxWidth;
- } else {
- self.toWidth = self.maxWidth;
- self.fromWidth = self.minWidth;
- document.getElementById("resize").style.display = 'none';
- }
- }
- this.flipHeight = function ()
- {
- if (self.toHeight == self.maxHeight) {
- self.toHeight = self.minHeight;
- self.fromHeight = self.maxHeight;
- } else {
- document.getElementById("mainStretchingBody").style.height = '130px';
- document.getElementById("mainStretchingBodyRight").style.height = '130px';
- document.getElementById("mainBodyBreak").style.height = '130px';
- document.getElementById("bottomHighlightDiv").style.top = '212px';
- if (window.widget) window.resizeTo(306, 243);
- self.toHeight = self.maxHeight;
- self.fromHeight = self.minHeight;
- }
- }
- this.stretch = function (event)
- {
- this.multiplier = 1;
- if (event.shiftKey)
- this.multiplier = 10;
- if (this.stretchAnimator) {
- }
- this.stretchAnimator = new AppleAnimator(this.duration * this.multiplier, 13, this.fromWidth, this.toWidth, this.nextFrame);
- this.stretchAnimatorHeight = new AppleAnimator(this.duration * this.multiplier, 13, this.fromHeight, this.toHeight, this.nextFrameHeight);
- this.stretchAnimator.oncomplete = this.flipWidth;
- this.stretchAnimatorHeight.oncomplete = this.flipHeight;
- this.stretchAnimator.start();
- this.stretchAnimatorHeight.start();
- }
- }
- function setPreferencesWhatToCopy(whatToSet)
- {
- preferencesWhatToCopy=whatToSet;
- }
- function showBack(event) {
- if (window.widget) {
- widget.prepareForTransition("ToBack");
- }
- document.getElementById("front").style.display = "none";
- document.getElementById("back").style.display = "block";
- if (window.widget) {
- setTimeout("widget.performTransition()", 0);
- }
- }
- function showFront(event) {
- if (window.widget) {
- widget.prepareForTransition("ToFront");
- }
- document.getElementById("back").style.display = "none";
- document.getElementById("front").style.display = "block";
- if (window.widget) {
- setTimeout("widget.performTransition()", 0);
- }
- }
- function setLocalization()
- {
- if (window.widget) {
- try {
- var calc=widget.calculator;
- gDecimalSeparator = calc.evaluateExpression ("decimal_string", 16);
- if (gDecimalSeparator===undefined) {
- } else if (gDecimalSeparator==',') {
- commaLocale=1;
- }
- } catch (ex) {}
- }
- }
- //Thanks was good, FlightMech is lame.
- //It's pretty late, and aim is to blame.
- //I talked to a guy, he worked at this place,
- //Where robots are built that fly around space.
- //They thought I was dumb, or so they told me.
- //But they just lost a satellite. Now that... is... irony.
-